package myJs.projectCps.volcanoPlot

import cats.effect.SyncIO
import com.softwaremill.quicklens._
import myJs.cps._
import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._

/** Created by yz on 3/11/2020
  */
object ColorCp {

  val plotO = Cp.plotO

  case class Props(
      basicData: plotO.ColorData,
      basicDataChange: (plotO.ColorData => plotO.ColorData) => SyncIO[Unit]
  ){
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>

    object FTool {

      def strChange(f: PathLazyModify[plotO.ColorData, String]) = (v: String) => {
        props.basicDataChange {
          f.setTo(v)
        }
      }

    }

    val basicData = props.basicData

    Fragment(
      MiniColorInlineCp.Props(
        label = "UP",
        value = basicData.up,
        onChange = FTool.strChange(modifyLens[plotO.ColorData](_.up)),
        name = s"up",
        labelWidth = 4,
        inputWidth = 8
      ).render,
      MiniColorInlineCp.Props(
        label = "DOWN",
        value = basicData.down,
        onChange = FTool.strChange(modifyLens[plotO.ColorData](_.down)),
        name = s"down",
        labelWidth = 4,
        inputWidth = 8
      ).render,
      MiniColorInlineCp.Props(
        label = "NONE",
        value = basicData.none,
        onChange = FTool.strChange(modifyLens[plotO.ColorData](_.none)),
        name = s"none",
        labelWidth = 4,
        inputWidth = 8
      ).render
    )

  }

}
